home *** CD-ROM | disk | FTP | other *** search
- Path: ibm32.perftech.com!usenet
- From: murf@perftech.com (John Murphy)
- Newsgroups: comp.lang.c++,comp.os.msdos.programmer
- Subject: Re: Timer (0x1C) Interrupt exactly 18.2 seconds?
- Date: 23 Feb 1996 14:00:07 GMT
- Organization: Performance Technology Inc
- Message-ID: <4gkh97$i44@ibm32.perftech.com>
- References: <4givrv$cim@midland.co.nz>
- NNTP-Posting-Host: k5zba.perftech.com
- Mime-Version: 1.0
- NNTP-Posting-User: REVCO
- X-Newsreader: WinVN 0.93.11
-
- In article <4givrv$cim@midland.co.nz>, lowefam@igrin.co.nz says...
- >
- >Hi
- >
- >I have a C++ Program (on DOS) in which a function is attached to the
- >Timer (0x1C) Interrupt.
- >
- >The function has a static int to count the number of times it has been
- >called. Every 'x' calls, It executes another function.
- >
- >'x' is 546, which one would expect to result in the function being
- >called every 30 seconds. However, it is called every 29 point
- >something seconds. Over 5 minutes you can see it has drifted. If I had
- >one to 'x' (now 547) it is called every 30 point something seconds -
- >the same problem in reverse.
- >
- >This program is expected to run, continually, for YEARS - so a drift
- >that shows up in 5 minutes will make it unusable.
- >
- >Does anybody have any ideas WHY this is happening?
- >
- The timer tick, as you have discovered, does NOT occur exactly 18.2 ticks
- per second. It is derived from a 1.19318 MHz oscillator divided by 64K, so
- it's closer to 18.2065 times per second.
-
- Try something like this in your tick interrupt code:
-
- {
- static long accumulator = 0;
-
-
- accumulator += 0x10000; /* Number of oscillator cycles per tick */
- if ( accumulator >= 1193180 * 30 ) {
- accumulator -= 1193180 * 30;
- /* call your "once every 30 seconds" function */
- }
- }
-
- Then you'll get a timeout in a little less than 30 seconds sometimes and a
- little more than 30 seconds other times, but the long term average will be
- pretty good.
-
- Murf
-
-